﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {

        static void Main(string[] args)
        {
            test();
            test1();
            test2();
            test3();
            test4();
            test5();
            test6();
            test7();
            test8();
        }

        public static void test()
        {
            //在 Main 方法中创建一个字符串类型的数组，并存入 5 个值，然后将数组中下标是偶数的元素输出。
            string[] arr1 = new string[5];
            arr1[0] = "1";
            arr1[1] = "2";
            arr1[2] = "3";
            arr1[3] = "4";
            arr1[4] = "5";
            for (int i = 0; i < arr1.GetLength(0); i++)
            {
                if (i % 2 != 0)
                {
                    Console.WriteLine("是偶数" + arr1[i]);
                }
            }

        }
        public static void test1()
        {
            //输入一行字符串，分别统计出其中英文字母、数字、空格的个数。
            string adc = "asdsa1234    ";
            int aa = 0;
            int bb = 0;
            int cc = 0;
            foreach (char num in adc)
            {
                if (char.IsLetter(num))
                {
                    aa++;
                }
                else if (char.IsDigit(num))
                {
                    bb++;
                }
                else if (char.IsWhiteSpace(num))
                {
                    cc++;
                }
            }
            Console.WriteLine("其中英文字母{0}数字{1}空格的个数{2}" + aa + bb + cc);
        }
        public static void test2()
        {
            //            在 Main 方法中创建一个 double 类型的数组，并在该数组中存入 5 名学生的考试成绩(控制台输入)，计算总成绩和平均成绩。
            //要求使用foreach语句实现该功能，

            double[] arr = new double[5];

            for (int i = 0; i < arr.Length; i++)
            {
                Console.WriteLine("请输入" + (i + 1) + " 名学生的考试成绩");
                string a = Console.ReadLine();
                arr[i] = int.Parse(a);
            }
            double sum = 0;
            foreach (int item in arr)
            {

                sum += item;
            }
            Console.WriteLine("总成绩" + sum);
            Console.WriteLine("平均成绩" + sum / 5);
        }


        public static void test3()
        {
            //定义一个方法，实现一维数组的排序功能，从大到小排序。(不要用Array类的方法)
            int[] arr = { 2, 9, 8, 4, 5, 7, 11 };
            int stee = 0;
            int adad = arr.Length - 1;
            for (int i = 0; i < arr.Length - 1; i++)
            {
                for (int j = 0; i < arr.Length - 1 - i; j++)
                {
                    if (arr[j] < arr[j + 1])
                    {
                        int num;
                        num = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = num;
                    }
                }
            }
            for (int i = 0; i < arr.Length; i++)
            {
                Console.Write(arr[i] + "  ");
            }



        }

        public static void test4()
        {
            //            实现查找数组元素索引的功能。
            //定义一个数组，然后控制台输入要查找的元素，返回输入值在数组中最后一次出现的位置。若是找不到，请打印找不到。
            int[] arr = { 2, 9, 8, 4, 5, 7, 11, 2 };
            string aa = Console.ReadLine();
            int a1 = int.Parse(aa);


            for (int i = 0; i < arr.Length; i++)
            {
                if (a1 == arr[i])
                {
                    Console.WriteLine("" + Array.LastIndexOf(arr, a1));
                    break;
                }
                else if (a1 != arr[i])
                {
                    Console.WriteLine("找不到");
                }


            }
        }

        public static void test5()
        {
            {
                //用户输入正方形边长，用* 打印出实心正方形。
                Console.WriteLine("请输入边长");
                string a = Console.ReadLine();

                int n = int.Parse(a);


                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        if (j == 0 || j == n - 1 || i == 0 || i == n - 1)
                        {
                            Console.Write("*");
                        }
                        else
                        {
                            Console.Write("*");
                        }

                    }
                    Console.WriteLine();


                }

            }
        }
        public static void test6()
        {
            //打印菱形
            Console.WriteLine("请输入边长");
            string a = Console.ReadLine();

            int n = int.Parse(a);
            for (int i = 1; i <= n; i++)
            {

                for (int j = 1; j <= n - i; j++)
                {

                    Console.Write("");

                }

                for (int z = 1; z <= i * 2 - 1; z++)
                {

                    Console.Write("*");

                }
                Console.WriteLine();

            }

            for (int i = 1; i <= 3; i++)
            {

                for (int j = 1; j <= i; j++)
                {

                    Console.Write("  ");

                }

                int y = 3;

                for (int z = 5; z >= 2 * i - 1; z--)
                {
                    Console.Write("*");

                }
                Console.WriteLine();

            }
        }



        public static void test7()
        {
            //打印空心正方形

            Console.WriteLine("请输入正方形的边长");
            int side = int.Parse(Console.ReadLine());

            for (int i = 0; i < side; i++)
            {
                for (int j = 0; j < side; j++)
                {
                    if (i == 0 || i == side - 1 || j == 0 || j == side - 1)
                    {
                        Console.Write("*");
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }
                Console.WriteLine();
            }
        }


        public static void test8()
        {
            int[] arr = { 54, 43, 32, 21 };

            Console.WriteLine("请输入一个插进数组的数");
            int index = int.Parse(Console.ReadLine());

            int[] arr1 = new int[arr.Length + 1];

            for (int i = 0; i < arr.Length; i++)
            {
                arr1[i] = arr[i];
            }
            arr1[arr1.Length - 1] = index;

            for (int i = 0; i < arr1.Length - 1; i++)
            {
                for (int j = 0; j < arr1.Length - i - 1; j++)
                {
                    if (arr1[j] < arr1[j + 1])
                    {
                        int temp = arr1[j];
                        arr1[j] = arr1[j + 1];
                        arr1[j + 1] = temp;
                    }
                }
            }
            for (int i = 0; i < arr1.Length; i++)
            {
                Console.Write(arr1[i] + " ");
            }
        }
    }
} 
    

    

       
    

    

